var fadeDelay, slidetimer, scrolltimer, con;
var autoPlay = false;
var bgimages = [];
init();
play();
function carousel(a){
    this.p = new pagination(a);
    this.s = new stage();
    this.selectedIndex = -1;
    this.busy = false
}

function pagination(a){
    this.buttons = [a];
    var b = 0;
    for (b = 0; b < a; b++) {
        this.buttons[b] = new pagebutton(b + 1)
    }
}

function pagebutton(a){
    this.id = "control" + a;
    this.elem = document.getElementById(this.id)
}

function stage(){
    this.frames = [5];
    this.frames[0] = new frame(1, true, 8);
    this.frames[1] = new frame(2, true, 8);
    this.frames[2] = new frame(3, true, 8);
    this.frames[3] = new frame(4, true, 8);
    this.frames[4] = new frame(5, true, 8)
}

function frame(b, a, f){
    this.id = "f" + b;
    this.elem = document.getElementById(this.id);
    this.activeOverlay = -1;
    this.imgLoaded = false;
    this.overlays = [f];
    var d = 1;
    for (d; d <= f; d++) {
        var e = new overlay(this.id, d);
        this.overlays[d - 1] = e
    }
    if (a) {
        this.spots = [f];
        d = 1;
        for (d; d <= f; d++) {
            var g = new hotspot(this.id, d);
            this.spots[d - 1] = g
        }
    }
}

function hotspot(a, b){
    this.id = a + "h" + b;
    this.elem = document.getElementById(this.id)
}

function overlay(a, b){
    this.id = a + "t" + b;
    this.elem = document.getElementById(this.id)
}

function init(){
    var a = document.getElementById("numFrame").value;
    var b = "images";
    for (i = 0; i < a; i++) {
        bgimages[i] = document.getElementById(b + (i + 1)).value
    }
    con = new carousel(a);
    hit(1);
    con.s.frames[0].imgLoaded = true;
    con.selectedIndex = 1
}

function play(){
    if (autoPlay) {
        return
    }
    autoPlay = true;
    scrolltimer = setInterval(goToNextFrame, 5000)
}

function pause(){
    if (!autoPlay) {
        return
    }
    autoPlay = false;
    if (scrolltimer == undefined || scrolltimer == null) {
        return
    }
    clearInterval(scrolltimer);
    scrolltimer = null
}

function restart(){
    pause();
    play()
}

function goToNextFrame(){
    if (autoPlay) {
        var a = nextFrame();
        press(a, true)
    }
}

function nextFrame(){
    if (con.selectedIndex == bgimages.length) {
        return 1
    }
    else {
        if (con.selectedIndex < bgimages.length) {
            return ((con.selectedIndex * 1) + 1)
        }
        else {
            return 1
        }
    }
}

function prevFrame(){
    if (con.selectedIndex > 1) {
        return ((con.selectedIndex * 1) - 1)
    }
    else {
        return document.getElementById("numFrame").value
    }
}

function loadImgsilde(b){
    if (b != -1) {
        var a = con.s.frames[b - 1];
        if (a.imgLoaded) {
            return
        }
    }
    elem = document.getElementById(con.s.frames[b - 1].id);
    elem.style.backgroundImage = "url(" + bgimages[b - 1] + ")";
    con.s.frames[b - 1].imgLoaded = true
}

function hover(a){
    if (a == -1 || a == con.selectedIndex) {
        return
    }
    loadImgsilde(a);
    con.p.buttons[a - 1].elem.className = "on"
}

function unhit(a){
    if (a == -1) {
        return
    }
    con.p.buttons[a - 1].elem.className = "off"
}

function out(a){
    if (a == -1 || a == con.selectedIndex) {
        return
    }
    con.p.buttons[a - 1].elem.className = "off"
}

function hit(a){
    if (a == -1 || a == con.selectedIndex) {
        return
    }
    con.p.buttons[a - 1].elem.className = "selected"
}

function active(){
    if (con.selectedIndex == -1) {
        return
    }
    pause();
    updateFrame(true)
}

function deactive(){
    if (con.selectedIndex == -1) {
        return
    }
    var a = con.s.frames[con.selectedIndex - 1];
    if (a == null) {
        return
    }
    updateFrame(false);
    restart()
}

function updateFrame(d){
    var b = con.s.frames[con.selectedIndex - 1];
    if (b == null) {
        return
    }
    if (b.spots == null) {
        return
    }
    var a = b.spots.length;
    if (!d) {
        clearOverlay(b)
    }
    for (a; a > 0; a--) {
    }
}

function clearOverlay(a){
    if (a.activeOverlay != -1) {
        var b = a.overlays[a.activeOverlay - 1];
        hideOverlay(b.id);
        a.activeOverlay = -1
    }
}

function fadeOverlay(a){
    fadeDelay = setTimeout("hideOverlay('" + a + "')", 700);
    hideOtherVisibleOverlays(a)
}

function hideOtherVisibleOverlays(b){
    var e = b.substring(0, 2);
    var d = getElementsByClassName(document.getElementById(e), "a", "overlay");
    for (var a = 0; a < d.length; a++) {
        if (d[a].style.display == "block" && d[a].id != b) {
            d[a].style.display = "none"
        }
    }
}

function getElementsByClassName(b, g, a){
    var f = (g == "*" && b.all) ? b.all : b.getElementsByTagName(g);
    var j = new Array();
    a = a.replace(/\-/g, "\\-");
    var h = new RegExp("(^|\\s)" + a + "(\\s|$)");
    var e;
    for (var d = 0; d < f.length; d++) {
        e = f[d];
        if (h.test(e.className)) {
            j.push(e)
        }
    }
    return (j)
}

function hideOverlay(a){
    elem = document.getElementById(a);
    hide(elem);
    con.s.frames[con.selectedIndex - 1].activeOverlay = -1
}

function showOverlay(b, d){
    hideOtherVisibleOverlays(b);
    if (fadeDelay != undefined) {
        clearTimeout(fadeDelay);
        fadeDelay = undefined
    }
    if (con.s.frames[con.selectedIndex - 1].activeOverlay == d) {
        return
    }
    clearOverlay(con.s.frames[con.selectedIndex - 1]);
    var a = document.getElementById(b);
    show(a);
    con.s.frames[con.selectedIndex - 1].activeOverlay = d
}

function changeOpac(b, d){
    var a = document.getElementById(d).style;
    a.opacity = (b / 100);
    a.MozOpacity = (b / 100);
    a.KhtmlOpacity = (b / 100);
    a.filter = "alpha(opacity=" + b + ")"
}

function showLegal(){
    elem = document.getElementById("legal");
    show(elem)
}

function hideLegal(){
    elem = document.getElementById("legal");
    hide(elem)
}

function hide(a){
    if (a == null || a.style.display == "none") {
        return
    }
    a.style.display = "none"
}

function show(a){
    if (a == null || a.style.display == "block") {
        return
    }
    a.style.display = "block"
}

function press(b, a){
    if (con.busy || b == con.selectedIndex) {
        return
    }
    loadImgsilde(b);
    deactive();
    hit(b);
    unhit(con.selectedIndex);
    slide(b, a);
    con.selectedIndex = b
}

function slide(b, a){
    con.busy = true;
    if (slidetimer != undefined || slidetimer != null) {
        clearTimeout(slidetimer)
    }
    (a || b > con.selectedIndex) ? scrollRight(b, con.selectedIndex) : scrollLeft(b, con.selectedIndex)
}

function scrollRight(d, a){
    var b = document.getElementById("stage");
    b.style.left = "0px";
    reposition(a, 0);
    reposition(d, 1);
    reIndex(d, a);
    scroll(0, -990)
}

function scrollLeft(d, a){
    var b = document.getElementById("stage");
    b.style.left = "-715px";
    reposition(d, 0);
    reposition(a, 1);
    reIndex(d, a);
    scroll(-990, 0)
}

function reIndex(e, b){
    var d = 2;
    var a = con.s.frames.length;
    for (a; a > 0; a--) {
        if (a != e && a != b) {
            reposition(a, d++)
        }
    }
}

function reposition(b, a){
    con.s.frames[b - 1].elem.style.left = 990 * a + "px"
}

function scroll(d, a){
    var b = document.getElementById("stage");
    next = d, slidetimer = 0, interval = 50, speed = 40;
    if (d < a) {
        next += interval
    }
    else {
        if (d > a) {
            next -= interval
        }
    }
    if (next > 0 || (next < a && d > a) || (next > a && d < a)) {
        next = next > 0 ? 0 : a;
        b.style.left = next + "px";
        con.busy = false
    }
    else {
        b.style.left = next + "px";
        slidetimer = setTimeout("scroll(" + next + ", " + a + ")", speed)
    }
}

function onLinkClick(){
    window.open("http://pages.ebay.com/fashion/index.html", "mywindow", "resizable=1,scrollbars=1,width=990,height=600,left=200,top=300")
}

function highlightA(a){
    if (a.className == "arrow r-a") {
        a.className = "arrow r-h"
    }
    if (a.className == "arrow l-a") {
        a.className = "arrow l-h"
    }
}

function dehighlightA(a){
    if (a.className == "arrow r-h") {
        a.className = "arrow r-a"
    }
    else {
        if (a.className == "arrow l-h") {
            a.className = "arrow l-a"
        }
    }
}

function prevF(){
    if (con.busy || a == con.selectedIndex) {
        return
    }
    var a = prevFrame();
    loadImgsilde(a);
    deactive();
    hit(a);
    unhit(con.selectedIndex);
    con.busy = true;
    if (slidetimer != undefined || slidetimer != null) {
        clearTimeout(slidetimer)
    }
    scrollLeft(a, con.selectedIndex);
    con.selectedIndex = a
}

function nextF(){
    if (con.busy || a == con.selectedIndex) {
        return
    }
    var a = nextFrame();
    loadImgsilde(a);
    deactive();
    hit(a);
    unhit(con.selectedIndex);
    con.busy = true;
    if (slidetimer != undefined || slidetimer != null) {
        clearTimeout(slidetimer)
    }
    scrollRight(a, con.selectedIndex);
    con.selectedIndex = a
};
